/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package it.polimi.games.epkb.entityClasses;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author plebani
 */
@Entity
@Table(name = "observed_component")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "ObservedComponent.findAll", query = "SELECT o FROM ObservedComponent o"),
    @NamedQuery(name = "ObservedComponent.findByIdComponent", query = "SELECT o FROM ObservedComponent o WHERE o.observedComponentPK.idComponent = :idComponent"),
    @NamedQuery(name = "ObservedComponent.findByIdSensorType", query = "SELECT o FROM ObservedComponent o WHERE o.observedComponentPK.idSensorType = :idSensorType"),
    @NamedQuery(name = "ObservedComponent.findByServiceObjectId", query = "SELECT o FROM ObservedComponent o WHERE o.serviceObjectId = :serviceObjectId")})
public class ObservedComponent implements Serializable {
    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected ObservedComponentPK observedComponentPK;
    @Basic(optional = false)
    @Column(name = "ServiceObjectId")
    private String serviceObjectId;
    @JoinColumn(name = "Id_SensorType", referencedColumnName = "ID", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private SensorType sensorType;
    @JoinColumn(name = "Id_Component", referencedColumnName = "ID", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Component component;

    public ObservedComponent() {
    }

    public ObservedComponent(ObservedComponentPK observedComponentPK) {
        this.observedComponentPK = observedComponentPK;
    }

    public ObservedComponent(ObservedComponentPK observedComponentPK, String serviceObjectId) {
        this.observedComponentPK = observedComponentPK;
        this.serviceObjectId = serviceObjectId;
    }

    public ObservedComponent(String idComponent, String idSensorType) {
        this.observedComponentPK = new ObservedComponentPK(idComponent, idSensorType);
    }

    public ObservedComponentPK getObservedComponentPK() {
        return observedComponentPK;
    }

    public void setObservedComponentPK(ObservedComponentPK observedComponentPK) {
        this.observedComponentPK = observedComponentPK;
    }

    public String getServiceObjectId() {
        return serviceObjectId;
    }

    public void setServiceObjectId(String serviceObjectId) {
        this.serviceObjectId = serviceObjectId;
    }

    public SensorType getSensorType() {
        return sensorType;
    }

    public void setSensorType(SensorType sensorType) {
        this.sensorType = sensorType;
    }

    public Component getComponent() {
        return component;
    }

    public void setComponent(Component component) {
        this.component = component;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (observedComponentPK != null ? observedComponentPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ObservedComponent)) {
            return false;
        }
        ObservedComponent other = (ObservedComponent) object;
        if ((this.observedComponentPK == null && other.observedComponentPK != null) || (this.observedComponentPK != null && !this.observedComponentPK.equals(other.observedComponentPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "it.polimi.games.epkb.entityClasses.ObservedComponent[ observedComponentPK=" + observedComponentPK + " ]";
    }
    
}
